package org.report4service.views;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;

import org.report4service.listeners.LogonListner;
import org.report4service.model.Report;
import org.report4service.utils.CommandPool;
import org.report4service.utils.MonthReportUtil;

/**
 * Form to display the monthly report
 * @author Jmpango
 * 
 */
public class MonthReportForm extends Canvas implements CommandListener {

    private MonthReportUtil monthReportUtil;

    /** Reference to display instance */
    private Display display;

    /** Reference to previous form */
    private Displayable prvScreen;

    /** Reference to application title */
    private String title;

    /** Reference to application logon listener */
    private LogonListner logonListner;

    private int month;

    private int year;
    private Report report;

    public MonthReportForm(Display display, Displayable prvScreen, String title,
	    LogonListner logonListner,int month, int year, Report report) {
	super();
	setDisplay(display);
	setPrvScreen(prvScreen);
	setTitle(title);
	setLogonListner(logonListner);
        setMonth(month);
        setYear(year);
        setReport(report);
	//this.setFullScreenMode(false);
	
	monthReportUtil = new MonthReportUtil(getMonth(), getYear(), this.getWidth(), this.getHeight(),getReport());
	monthReportUtil.initializeMonthReport();
	
	addCommand(CommandPool.btnBack);
	setCommandListener(this);
	
	getDisplay().setCurrent(this);

    }

    protected void paint(Graphics g) {
	g.setColor(0xffffff);
	g.fillRect(0, 0, this.getWidth(), this.getHeight());
	monthReportUtil.paint(g);
    }

    public void commandAction(Command command, Displayable arg1) {
	if(command.equals(CommandPool.btnBack))
            cleanUp();
	    getDisplay().setCurrent(getPrvScreen());
    }

    private void cleanUp(){
      monthReportUtil = null;
      title = "";
      logonListner = null;
      report = null;
    }

    /**
     * @return the monthReportUtil
     */
    public MonthReportUtil getMonthReportUtil() {
	return monthReportUtil;
    }

    /**
     * @param monthReportUtil
     *            the monthReportUtil to set
     */
    public void setMonthReportUtil(MonthReportUtil monthReportUtil) {
	this.monthReportUtil = monthReportUtil;
    }

    /**
     * @return the display
     */
    public Display getDisplay() {
	return display;
    }

    /**
     * @param display
     *            the display to set
     */
    public void setDisplay(Display display) {
	this.display = display;
    }

    /**
     * @return the prvScreen
     */
    public Displayable getPrvScreen() {
	return prvScreen;
    }

    /**
     * @param prvScreen
     *            the prvScreen to set
     */
    public void setPrvScreen(Displayable prvScreen) {
	this.prvScreen = prvScreen;
    }

    /**
     * @return the title
     */
    public String getTitle() {
	return title;
    }

    /**
     * @param title
     *            the title to set
     */
    public void setTitle(String title) {
	this.title = title;
    }

    /**
     * @return the logonListner
     */
    public LogonListner getLogonListner() {
	return logonListner;
    }

    /**
     * @param logonListner
     *            the logonListner to set
     */
    public void setLogonListner(LogonListner logonListner) {
	this.logonListner = logonListner;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public Report getReport() {
        return report;
    }

    public void setReport(Report report) {
        this.report = report;
    }

}
